﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.MovieRecorder.CApMRCRecorderSettingsPreviewOverlayViewModel
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.ComponentModel;
using System.Drawing;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Media;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.MovieRecorder;

public class CApMRCRecorderSettingsPreviewOverlayViewModel : INotifyPropertyChanged
{
  private CApMRCRecorderSettingsViewModel _settingsViewModel;
  private double _width;
  private double _height;
  private const int OFFSET_X = 10;
  private const int OFFSET_Y = 10;

  public CApMRCRecorderSettingsPreviewOverlayViewModel(
    CApMRCRecorderSettingsViewModel settingsViewModel)
  {
    this._settingsViewModel = settingsViewModel;
    this.UpdatePosition();
  }

  public event PropertyChangedEventHandler PropertyChanged;

  protected virtual void OnPropertyChanged(string propertyName)
  {
    if (this.PropertyChanged == null)
      return;
    this.PropertyChanged((object) this, new PropertyChangedEventArgs(propertyName));
  }

  public Visibility IsVisible
  {
    get
    {
      return !this.OverlayTextVisible && !this.OverlayImageVisible ? Visibility.Collapsed : Visibility.Visible;
    }
  }

  public bool OverlayTextVisible => this._settingsViewModel.OverlayText != string.Empty;

  public string OverlayText
  {
    get => this._settingsViewModel.OverlayText;
    set
    {
      this.OnPropertyChanged(nameof (OverlayText));
      this.OnPropertyChanged("OverlayTextVisible");
      this.OnPropertyChanged("OverlayTextMargin");
    }
  }

  public short OverlayFontSize
  {
    get => this._settingsViewModel.OverlayFontSize;
    set => this.OnPropertyChanged(nameof (OverlayFontSize));
  }

  public System.Windows.Media.Brush OverlayFontColor
  {
    get => (System.Windows.Media.Brush) new SolidColorBrush(this._settingsViewModel.OverlayFontColor);
    set => this.OnPropertyChanged(nameof (OverlayFontColor));
  }

  public System.Windows.Media.Color OverlayFontShadowColor
  {
    get => this._settingsViewModel.OverlayFontShadowColor;
    set => this.OnPropertyChanged(nameof (OverlayFontShadowColor));
  }

  public VerticalAlignment OverlayTextVerticalAlignment
  {
    get
    {
      if (!this.OverlayTextVisible)
        return VerticalAlignment.Stretch;
      switch ((int) this._settingsViewModel.OverlayPosition)
      {
        case 0:
        case 1:
        case 2:
        case 4:
          return VerticalAlignment.Top;
        case 6:
        case 7:
        case 8:
          return VerticalAlignment.Bottom;
        default:
          return VerticalAlignment.Center;
      }
    }
  }

  public Dock OverlayImageDock
  {
    get
    {
      if (this.OverlayImageVisible)
      {
        switch ((int) this._settingsViewModel.OverlayPosition)
        {
          case 0:
          case 3:
          case 6:
            return Dock.Left;
          case 1:
            return Dock.Top;
          case 2:
          case 5:
          case 8:
            return Dock.Right;
          case 4:
            return Dock.Top;
          case 7:
            return Dock.Bottom;
        }
      }
      return Dock.Left;
    }
  }

  public Thickness OverlayTextMargin
  {
    get
    {
      if (!this.OverlayImageVisible)
        return new Thickness(0.0);
      switch ((int) this._settingsViewModel.OverlayPosition)
      {
        case 0:
        case 3:
        case 6:
          return new Thickness(15.0, 0.0, 0.0, 0.0);
        case 1:
        case 4:
          return new Thickness(0.0, 15.0, 0.0, 0.0);
        case 2:
        case 5:
        case 8:
          return new Thickness(0.0, 0.0, 15.0, 0.0);
        case 7:
          return new Thickness(0.0, 0.0, 0.0, 15.0);
        default:
          return new Thickness(0.0);
      }
    }
  }

  public double OverlayImageWidth
  {
    get
    {
      return (double) this._settingsViewModel.OverlayImageWidth.Percent(this._settingsViewModel.OverlayImageSizePercent);
    }
  }

  public double OverlayImageHeight
  {
    get
    {
      return (double) this._settingsViewModel.OverlayImageHeight.Percent(this._settingsViewModel.OverlayImageSizePercent);
    }
  }

  public double OverlayImageTransparency
  {
    get => 1.0 - (double) this._settingsViewModel.OverlayImageTransparency / 100.0;
  }

  public void UpdateImage()
  {
    this.OnPropertyChanged("OverlayImageWidth");
    this.OnPropertyChanged("OverlayImageHeight");
    this.OnPropertyChanged("OverlayImageTransparency");
  }

  public bool OverlayImageVisible => this._settingsViewModel.AllowEditOverlayImage;

  public string OverlayImagePath
  {
    get => this._settingsViewModel.OverlayImagePath;
    set
    {
      this.OnPropertyChanged(nameof (OverlayImagePath));
      this.OnPropertyChanged("OverlayImageVisible");
      this.UpdateImage();
    }
  }

  public VerticalAlignment OverlayImageVerticalAlignment
  {
    get
    {
      if (this.OverlayImageVisible)
      {
        TxMovieOverlayPosition overlayPosition = this._settingsViewModel.OverlayPosition;
        if (overlayPosition <= 2)
        {
          if (overlayPosition == null || overlayPosition == 2)
            return VerticalAlignment.Top;
        }
        else if (overlayPosition == 6 || overlayPosition == 8)
          return VerticalAlignment.Bottom;
      }
      return VerticalAlignment.Center;
    }
  }

  public double Top { get; set; }

  public double Left { get; set; }

  public double Width
  {
    get => this._width;
    set
    {
      if (this._width == value)
        return;
      this._width = value;
      this.UpdatePosition();
    }
  }

  public double Height
  {
    get => this._height;
    set
    {
      if (this._height == value)
        return;
      this._height = value;
      this.UpdatePosition();
    }
  }

  public void UpdatePosition()
  {
    Screen applicationFrameScreen = CApMRCRecorderUtilities.GetApplicationFrameScreen();
    double num1 = (double) applicationFrameScreen.WorkingArea.Top;
    double num2 = (double) applicationFrameScreen.WorkingArea.Left;
    switch ((int) this._settingsViewModel.OverlayPosition)
    {
      case 0:
        num1 += 10.0;
        num2 += 10.0;
        break;
      case 1:
        num1 += 10.0;
        num2 += ((double) applicationFrameScreen.WorkingArea.Width - this.Width) / 2.0;
        break;
      case 2:
        num1 += 10.0;
        num2 += (double) applicationFrameScreen.WorkingArea.Width - this.Width - 10.0;
        break;
      case 3:
        num1 += ((double) applicationFrameScreen.WorkingArea.Height - this.Height) / 2.0;
        num2 += 10.0;
        break;
      case 4:
        Rectangle workingArea1;
        if (this.OverlayImageVisible && !this.OverlayTextVisible || !this.OverlayImageVisible && this.OverlayTextVisible)
        {
          double num3 = num1;
          workingArea1 = applicationFrameScreen.WorkingArea;
          double num4 = ((double) workingArea1.Height - this.Height) / 2.0;
          num1 = num3 + num4;
        }
        else
        {
          double num5 = num1;
          workingArea1 = applicationFrameScreen.WorkingArea;
          double num6 = (double) (workingArea1.Height / 2) - this.OverlayImageHeight;
          num1 = num5 + num6;
        }
        double num7 = num2;
        workingArea1 = applicationFrameScreen.WorkingArea;
        double num8 = ((double) workingArea1.Width - this.Width) / 2.0;
        num2 = num7 + num8;
        break;
      case 5:
        double num9 = num1;
        Rectangle workingArea2 = applicationFrameScreen.WorkingArea;
        double num10 = ((double) workingArea2.Height - this.Height) / 2.0;
        num1 = num9 + num10;
        double num11 = num2;
        workingArea2 = applicationFrameScreen.WorkingArea;
        double num12 = (double) workingArea2.Width - this.Width - 10.0;
        num2 = num11 + num12;
        break;
      case 6:
        num1 += (double) applicationFrameScreen.WorkingArea.Height - this.Height - 10.0;
        num2 += 10.0;
        break;
      case 7:
        double num13 = num1;
        Rectangle workingArea3 = applicationFrameScreen.WorkingArea;
        double num14 = (double) workingArea3.Height - this.Height - 10.0;
        num1 = num13 + num14;
        double num15 = num2;
        workingArea3 = applicationFrameScreen.WorkingArea;
        double num16 = ((double) workingArea3.Width - this.Width) / 2.0;
        num2 = num15 + num16;
        break;
      case 8:
        double num17 = num1;
        Rectangle workingArea4 = applicationFrameScreen.WorkingArea;
        double num18 = (double) workingArea4.Height - this.Height - 10.0;
        num1 = num17 + num18;
        double num19 = num2;
        workingArea4 = applicationFrameScreen.WorkingArea;
        double num20 = (double) workingArea4.Width - this.Width - 10.0;
        num2 = num19 + num20;
        break;
    }
    this.Top = num1;
    this.OnPropertyChanged("Top");
    this.Left = num2;
    this.OnPropertyChanged("Left");
    this.OnPropertyChanged("OverlayImageDock");
    this.OnPropertyChanged("OverlayTextMargin");
    this.OnPropertyChanged("OverlayImageVerticalAlignment");
    this.OnPropertyChanged("OverlayTextVerticalAlignment");
  }
}
